package com.lineage.william;

import com.lineage.DatabaseFactory;
import com.lineage.server.model.Instance.L1ItemInstance;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;

public class WilliamItemMessage {
  private static ArrayList<ArrayList<Object>> list = new ArrayList<>();
  
  public static ArrayList<String> getItemInfo(L1ItemInstance item) {
    ArrayList<String> a = new ArrayList<>();
    Iterator<ArrayList<Object>> iterator = list.iterator();
    while (iterator.hasNext()) {
      ArrayList<Object> objects = iterator.next();
      int itemid = ((Integer)objects.get(0)).intValue();
      if (itemid == -1 || itemid == item.getItemId())
        a.add((String)objects.get(1)); 
    } 
    return a;
  }
  
  public static void getData() {
    Connection con = null;
    try {
      con = DatabaseFactory.get().getConnection();
      Statement stat = con.createStatement();
      ResultSet rset = stat.executeQuery("SELECT * FROM w_自订物品显示");
      ArrayList<Object> aReturn = null;
      if (rset != null)
        while (rset.next()) {
          aReturn = new ArrayList();
          aReturn.add(0, new Integer(rset.getInt("Item_Id")));
          aReturn.add(1, rset.getString("Info"));
          list.add(aReturn);
        }  
      if (con != null && !con.isClosed())
        con.close(); 
    } catch (Exception exception) {}
  }
}
